package org.dy.servlet.mvc.json;

import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.dy.servlet.mvc.Controller;
import org.dy.servlet.mvc.ModelAndView;

@SuppressWarnings("serial")
public class JSONController extends Controller {
	
	@Override
	protected void renderView(HttpServletRequest request, HttpServletResponse response, 
			ModelAndView view) throws IOException, ServletException {
		// TODO Auto-generated method stub
		Writer writer = response.getWriter();
		if(view != null){
			Map map = view.getMap();
			JSONObject obj = JSONObject.fromObject(map);
			writer.write(obj.toString());		
		}
		writer.close();
	}

}
